package cn.edu.jxnu.sse.dao;

import cn.edu.jxnu.sse.utils.DBUtil;
import cn.edu.jxnu.sse.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
    public User findUserByName(String username) {
        User u = null;
        Connection conn = DBUtil.getConnection();
        try {
            PreparedStatement pst = conn.prepareStatement("select * from usr_t where user_name=?");
            pst.setString(1, username);
            ResultSet rst = pst.executeQuery();
            if(rst.next()){
                u = new User();
                u.setUserName(username);
                u.setPassword(rst.getString("pwd"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return u;
    }
}
